package cn.hfatec.shms.system.codeType.action;

import cn.hfatec.shms.base.ShmsBaseAction;
import cn.hfatec.shms.system.codeInfo.model.CodeInfoParams;
import cn.hfatec.shms.system.codeInfo.service.CodeInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import cn.hfatec.JsonResponse;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.freemarker.FreeMarkerUtil;
import cn.hfatec.shms.system.codeType.service.CodeTypeService;
import cn.hfatec.base.BaseAction;
import org.springframework.ui.Model;



/**
 *
 * @author hfatec codegen
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Controller
@RequestMapping("/system/codeType")
public class CodeTypeAction extends ShmsBaseAction {

    //服务层
    @Resource(name = "CodeTypeService")
    private CodeTypeService codeTypeService;
    //服务层
    @Resource(name = "CodeInfoService")
    private CodeInfoService codeInfoService;

    /**
     *
     * 查询列表
     *
     */
    @RequestMapping("/list")
    public String list( String codeTypeId,String codeTypeName, Page page, Model model) {

        Table table = codeTypeService.queryCodeTypeTable(codeTypeId,codeTypeName, page);
        List tableInfo = codeInfoService.queryCodeInfoTable(new String[]{});
        model.addAttribute("codeTypesTable", table);
        model.addAttribute("codeInfoTable", tableInfo);
        return "/system/codeType/list";
    }

    /**
     *
     * 异步查询列表
     *
     */
    @RequestMapping("/ajaxList")
    @ResponseBody
    public String ajaxList(String codeTypeId,String codeTypeName, Page page, Model model) {
        try {
            list(codeTypeId,codeTypeName, page, model);
            return new JsonResponse<Map>(JsonResponse.RETURN_SUCCESS, "", FreeMarkerUtil.render("/system/codeType/table", model)).toString();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonResponse.error;
    }
}
